﻿using System.IO;
using cfg;
using QFramework;
using SimpleJSON;
using UnityEngine;

namespace XCZProject
{
    public class ConfigSystem:AbstractSystem
    {
        /// <summary>
        /// 关卡配置
        /// </summary>
        public TbLevelConfig LevelConfig;

        /// <summary>
        /// 角色技能配置
        /// </summary>
        public TbAbilityConfig AbilityConfig;

        /// <summary>
        /// 角色技能升级加成配置
        /// </summary>
        public TbAbilityUpgradeConfig AbilityUpgradeConfig;

        /// <summary>
        /// 物品表配置
        /// </summary>
        public TbGoods GoodsConfig;
        
        protected override void OnInit()
        {
            Debug.Log("开始初始化配置表");
            // 初始化配置表
            string gameConfDir = Application.dataPath+"\\Art\\Config"; // 替换为gen.bat中outputDataDir指向的目录
            var tables = new cfg.Tables(file => JSON.Parse(File.ReadAllText($"{gameConfDir}/{file}.json")));
            LevelConfig = tables.TbLevelConfig;
            AbilityConfig = tables.TbAbilityConfig;
            AbilityUpgradeConfig = tables.TbAbilityUpgradeConfig;
            GoodsConfig = tables.TbGoods;
            
            Debug.Log("配置表初始化完成！");
        }
    }
}